public class Solution2331 {

    public static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }

    public boolean evaluateTree(TreeNode root) {
        if (root.left==null){
            return root.val==1;
        }else {
            return root.val==2?evaluateTree(root.left)|evaluateTree(root.right):evaluateTree(root.left)&evaluateTree(root.right);
        }
    }

    public static void main(String[] args) {
        System.out.println(new Solution2331().evaluateTree(new TreeNode(2,new TreeNode(1),new TreeNode(3,new TreeNode(0),new TreeNode(1)))));
    }
}
